package com.keshihao.eduservice.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.keshihao.commonutils.R;
import com.keshihao.eduservice.entity.EduCourse;
import com.keshihao.eduservice.entity.EduTeacher;
import com.keshihao.eduservice.service.EduCourseService;
import com.keshihao.eduservice.service.EduTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author Mr.Keshihao
 * @Date 2020/6/15 11:28
 * @Version 1.0
 */
@CrossOrigin
@RestController
@RequestMapping("/eduservice/indexfront")
public class IndexFrontController {

  @Autowired
  private EduCourseService courseService;
  @Autowired
  private EduTeacherService teacherService;

  //查询前8条热门课程，查询前4条名师
  @GetMapping("/index")
  public R index() {

    // 查询前8条热门课程记录
    QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
    wrapper.orderByDesc("id");
    wrapper.last("limit 8");
    List<EduCourse> eduList = courseService.list(wrapper);

    // 查询前4条名师记录
    QueryWrapper<EduTeacher> wrapperTeacher = new QueryWrapper<>();
    wrapperTeacher.orderByDesc("id");
    wrapperTeacher.last("limit 4");
    List<EduTeacher> teacherList = teacherService.list(wrapperTeacher);

    return R.ok().data("eduList",eduList).data("teacherList",teacherList);

  }

}
